//
//  TourisModuleViewModel.swift
//  AirTravel
//
//  Created by apple on 2021/7/23.
//

import UIKit

protocol TourisModuleDelegate:NSObjectProtocol {
    func tourisModuleClick(data:NSDictionary)
}

class TourisModuleViewModel: NSObject {
    
    var collView : UICollectionView?
    weak var delegate: TourisModuleDelegate?
    var dataSouce : Array<Any>?
    let identifyTM = "TourismModuleColl"
    
    
    func bindViewToViewModel(collView : UICollectionView) {
        self.collView = collView
        self.collView?.dataSource = self
        self.collView?.delegate = self
//        self.collView?.backgroundColor = UIColor.groupTableViewBackground
        let layout = UICollectionViewFlowLayout.init()
        layout.scrollDirection = .vertical
        
        layout.itemSize = .init(width: (SCREEN_WIDTH - 102) / 5, height: (SCREEN_WIDTH - 102) / 5 + 30)
        layout.minimumInteritemSpacing = 8
        layout.minimumLineSpacing = 10
        layout.sectionInset = UIEdgeInsets.init(top: 10, left: 17, bottom: 10, right: 17)
        self.collView?.isScrollEnabled = false
        self.collView?.collectionViewLayout = layout
        self.collView?.showsVerticalScrollIndicator = true
        
        self.collView?.register(UINib.init(nibName: "TourismModuleColl", bundle: nil), forCellWithReuseIdentifier: identifyTM)
    }
}

extension TourisModuleViewModel:UICollectionViewDataSource,UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return  10
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell : TourismModuleColl = collectionView.dequeueReusableCell(withReuseIdentifier: identifyTM, for: indexPath) as! TourismModuleColl
        cell.img.isUserInteractionEnabled = true
        let tap1=UITapGestureRecognizer.init(target: self, action: #selector(tapClick(tap:)))

        cell.img.addGestureRecognizer(tap1)
        switch indexPath.row {
        case 0:
            cell.titleLab.text = "跟团游"
            cell.img.image = UIImage(named: "跟团游")
            
        case 1:
            cell.titleLab.text = "自由行"
            cell.img.image = UIImage(named: "自由行")
        case 2:
            cell.titleLab.text = "邮轮游"
            cell.img.image = UIImage(named: "游轮游")
        case 3:
            cell.titleLab.text = "私家团"
            cell.img.image = UIImage(named: "私家团")
        case 4:
            cell.titleLab.text = "周边游"
            cell.img.image = UIImage(named: "周边游")
        case 5:
            cell.titleLab.text = "门票"
            cell.img.image = UIImage(named: "门票")
        case 6:
            cell.titleLab.text = "周边跟团"
            cell.img.image = UIImage(named: "周边跟团")
        case 7:
            cell.titleLab.text = "亲子游学"
            cell.img.image = UIImage(named: "亲子游学")
        case 8:
            cell.titleLab.text = "主题旅游"
            cell.img.image = UIImage(named: "主题旅游")
    
        default:
            cell.titleLab.text = "一日游"
            cell.img.image = UIImage(named: "一日游")
        }

        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){
    }
    
    @objc func tapClick(tap:UITapGestureRecognizer){
        let vc = TravelSearchCenterController()
        vc.currCityIndex = "0"
        currentVc()?.navigationController?.pushViewController(vc, animated: true)
    }
    
}
